package com.ruoyi.reports.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.reports.domain.TbReports;
import com.ruoyi.reports.mapper.TbReportsMapper;
import com.ruoyi.reports.service.ITbReportsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * 举报Service业务层处理
 * 
 * @author 劳雅玲
 * @date 2024-04-28
 */
@Service
public class TbReportsServiceImpl implements ITbReportsService 
{
    @Autowired
    private TbReportsMapper tbReportsMapper;

    /**
     * 查询举报
     * 
     * @param id 举报主键
     * @return 举报
     */
    @Override
    public TbReports selectTbReportsById(String id)
    {
        return tbReportsMapper.selectTbReportsById(id);
    }

    /**
     * 查询举报列表
     * 
     * @param tbReports 举报
     * @return 举报
     */
    @Override
    public List<TbReports> selectTbReportsList(TbReports tbReports)
    {
        return tbReportsMapper.selectTbReportsList(tbReports);
    }

    /**
     * 新增举报
     * 
     * @param tbReports 举报
     * @return 结果
     */
    @Override
    public int insertTbReports(TbReports tbReports)
    {
        if(!Objects.isNull(tbReports.getPostId())&&!Objects.isNull(tbReports.getUserId())){
            TbReports tbReports1 = new TbReports();
            tbReports1.setUserId(tbReports.getUserId());
            tbReports1.setPostId(tbReports.getPostId());
            List<TbReports> tbReports2 = selectTbReportsList(tbReports1);
            if (!tbReports2.isEmpty()){
                throw new RuntimeException("你已经举报过啦,等待管理员审核");
            }
        }
        tbReports.setCreateTime(DateUtils.getNowDate());
        return tbReportsMapper.insertTbReports(tbReports);
    }

    /**
     * 修改举报
     * 
     * @param tbReports 举报
     * @return 结果
     */
    @Override
    public int updateTbReports(TbReports tbReports)
    {
        tbReports.setUpdateTime(DateUtils.getNowDate());
        return tbReportsMapper.updateTbReports(tbReports);
    }

    /**
     * 批量删除举报
     * 
     * @param ids 需要删除的举报主键
     * @return 结果
     */
    @Override
    public int deleteTbReportsByIds(String[] ids)
    {
        return tbReportsMapper.deleteTbReportsByIds(ids);
    }

    /**
     * 删除举报信息
     * 
     * @param id 举报主键
     * @return 结果
     */
    @Override
    public int deleteTbReportsById(String id)
    {
        return tbReportsMapper.deleteTbReportsById(id);
    }
}
